<template>
	<view class="mainbgc">
		<backtop ref="backtops"></backtop>
		<u-sticky bgColor="#fff">
			<!-- 头部吸顶 -->
			<u-tabs :list="list1" :current="current" itemStyle="height:68rpx; padding: 0rpx 28rpx 0rpx 28rpx;"
				@click="onClick"></u-tabs>
		</u-sticky>
		<!-- 物流单号弹窗 -->
		<u-modal :show="show_wu" title="物流信息" confirmText="点击复制物流单号" @confirm="copycontent(wuliu.express_no)" confirmColor="#228dff" closeOnClickOverlay @close="show_wu=false">
			<view class="mainpadding">
				<view class="margin_top flexcenter strongtext">公司名称：{{wuliu.expressinfo.name}}</view>
				<view class="margin_top flexcenter strongtext">公司地址：{{wuliu.expressinfo.address}}</view>
				<view class="margin_top flexcenter strongtext">联系人：{{wuliu.expressinfo.lxrname}}</view>
				<view class="margin_top flexcenter strongtext">联系电话：{{wuliu.expressinfo.lxrmobile}}</view>
				<view class="margin_top flexcenter strongtext">物流单号：{{wuliu.express_no}}</view>
			</view>
		</u-modal>
		<view class="flexcenter" style="margin-top: 200rpx;" v-if="!list.data.length">
			<view class="placeimage"></view>
		</view>
		<view class="" v-if="list.data.length">
			<view class="list_child margin_top" v-for="item in list.data" :key="item.id" @click="details(item.id)"
				v-if="current!=4">
				<view>
					<view class="code flexbetween">
						<view class="ppbh">订单编号：{{item.order_no}}</view>
						<view class="daifukuan" v-if="item.state==1 && current!=4">待付款</view>
						<view class="daifahuo" v-if="item.state==2 && current!=4">待发货</view>
						<view class="daishouhuo" v-if="item.state==3 && current!=4">待收货</view>
						<view class="daipingjia" v-if="item.state==4 && current!=4">待评价</view>
						<!-- <view class="daifahuo" v-if="item.state!=4 && item.state!=8  && current==4">退款中</view> -->
						<view class="daituikuan" v-if="item.state==6">已完成</view>
						<view class="daifukuan" v-if="item.state==7">已取消</view>
					</view>
					<view class="top flexleft flexstart" v-for="ite in item.goods" :key="item.id">
						<view class="left">
							<image :src="ite.image_text" mode=""></image>
						</view>
						<view class="right">
							<view class="right_top">
								<view class="name">{{ite.title}}</view>
								<view class="size">{{ite.difference}}</view>
							</view>
							<view class="flexbetween right_jiage">
								<view class="word_red">￥{{ite.price}}</view>
								<view class="num">x{{ite.number}}</view>
							</view>
						</view>
					</view>
				</view>
				<view class="flexright right_sum">共计{{item.goods_num}}件商品 合计<view class="word_red">￥{{item.total_price}}
					</view>
				</view>
				<view class="bottom flexright">
					<view class="flexleft">
						<view class="confirm" v-if="item.state==1" @click.stop="atoncepay(item)">立即支付</view>
						<view class="deldingdan" v-if="item.state==1 || item.state==2" @click.stop="cancelorder(item)">取消订单</view>
						<!-- <view class="deldingdan" v-if="item.state==2 || item.state==3">退货/售后</view> -->
						<view class="deldingdan">查看详情</view>
						<view class="deldingdan" v-if="item.state==3" @click.stop="lookwuliu(item)">查看物流</view>
						<view class="confirm" v-if="item.state==3" @click.stop="suresh(item)">确认收货</view>
						<!-- <view class="confirm" v-if="item.state==4" @click.stop="pingjia(item)">立即评价</view> -->
						<view class="deldingdan" v-if="item.state==6 || item.state==7" @click.stop="delOrder(item)">删除订单</view>
					</view>
				</view>
			</view>
			<view class="list_child margin_top" v-for="item in list.data" :key="item.id"
				@click="jumpdetail('/pages/mypage/tuihuoxq?id=',item.id)" v-if="current==4">
				<view>
					<view class="code flexbetween">
						<view class="ppbh">退货编号：{{item.refund_no}}</view>
						<view class="daifukuan" v-if="item.state==1 && current!=4">待付款</view>
						<view class="daifahuo" v-if="item.state==2 && current!=4">待发货</view>
						<view class="daishouhuo" v-if="item.state==3 && current!=4">待收货</view>
						<view class="daipingjia" v-if="item.state==4 && current!=4">待评价</view>
						<!-- <view class="daifahuo" v-if="item.state!=4 && item.state!=8  && current==4">退款中</view> -->
						<view class="daituikuan" v-if="item.state==6">已完成</view>
						<view class="daifukuan" v-if="item.state==7">已取消</view>
					</view>
					<view class="top flexleft flexstart">
						<view class="left">
							<image :src="item.goods.image_text" mode=""></image>
						</view>
						<view class="right">
							<view class="right_top">
								<view class="name">{{item.goods.title}}</view>
								<view class="size">{{item.goods.difference}}</view>
							</view>
							<view class="flexbetween right_jiage">
								<view class="word_red">￥{{item.goods.price}}</view>
								<view class="num">x{{item.goods.number}}</view>
							</view>
						</view>
					</view>
				</view>
				<!-- <view class="flexright right_sum">共计{{item.goods_num}}件商品 合计<view class="word_red">￥{{item.total_price}}
					</view>
				</view> -->
				<view class="bottom flexright">
					<view class="flexleft">
						<view class="deldingdan">查看详情</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 取消订单原因列表 -->
		<quxiaolypop :messageInfo="{cancelshow:cancelshow,value:1}" @surecancel="surecancel"></quxiaolypop>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				list1: [{
					name: '全部',
				}, {
					name: '待付款',
				}, {
					name: '待发货'
				}, {
					name: '待收货'
				}, {
					name: '退货/售后'
				}],
				current: 0,
				cancelshow: false,
				show_wu: false,
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				//取消订单开始
				qxly: {
					name: "",
					id: "",
				},
				//取消订单结束
				order_id: "",
				wuliu: {},
			}
		},
		onLoad(options) {
			this.current = options.current
		},
		onPageScroll(res) {
				if (res.scrollTop > 700) {
					this.$refs.backtops.isshow = true
				} else {
					this.$refs.backtops.isshow = false
				}
			},
		onShow() {
			this.init()
		},
		methods: {
			// 立即评价
			pingjia(item){
				uni.navigateTo({
					url:"/pages/mypage/fabiaopinglun?id="+item.id
				})
			},
			// 确认收货
			suresh(item) {
				httpRequest.modal('提示', '请再次确认', true, (res) => {
					if (res) {
						httpRequest.request('/api/order/confirmOrder', 'POST', {
							id: item.id,
						}).then(res => {
							httpRequest.toast(res.msg)
							this.init()
						})
					}
				})
			},
			// 删除订单
			delOrder(item) {
				httpRequest.modal('提示', '确定要删除当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/order/delOrder', 'POST', {
							id: item.id,
						}).then(res => {
							httpRequest.toast(res.msg)
							this.init()
						})
					}
				})
			},
			// 立即支付
			atoncepay(item) {
				let obj = {
					order_pay_no: item.order_pay_no,
					pay_price: item.pay_price,
				}
				uni.redirectTo({
					url: '/pages/shopping/querenqzf?msg=' + encodeURIComponent(JSON
						.stringify(obj))
				})
			},
			// 取消订单开始
			cancelorder(item) {
				this.order_id = item.id
				this.cancelshow = true
			},
			surecancel(e) {
				this.qxly = e
				httpRequest.request('/api/order/cancelOrder', 'POST', {
					order_id: this.order_id,
					cancelyy_id: this.qxly.id,
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg);
					if (res.code == 1) {
						this.init()
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			// 取消订单结束
			init(isPage, page) {
				let _this = this;
				let url = "/api/order/getOrderList"
				let data = {
					page: page || 1,
					limit: _this.limit,
					state: this.current,
				}
				if (this.current == 4) {
					url = "/api/order/refundList"
					delete data.state
				}
				httpRequest.request(url, 'POST', data, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}

				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			details(id) {
				uni.navigateTo({
					url: '/pages/mypage/wodeddxq?id=' + id
				})
			},
			lookwuliu(item) {
				this.wuliu = item
				this.show_wu = true
			},
			jumpdetail(url, id) {
				uni.navigateTo({
					url: url + id
				})
			},
			close() {
				this.show = false
				this.show_wu = false
			},
			onClick(e) { //顶部
				this.current = e.index;
				this.init();
			},
			copycontent(value) {
				this.show_wu = false
				uni.setClipboardData({
					data: value, //要被复制的内容
					success: () => {
						//复制成功的回调函数
						httpRequest.toast("复制成功")
					}
				});
			},
		}
	}
</script>

<style scoped lang="scss">
	.daituikuan {
		color: #1ab961;
	}



	.logistics {
		text-align: center;
		padding: 34rpx 119rpx 60rpx 119rpx;
	}

	.logistics_danhao {
		font-size: 40rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	.logistics_kuaidi {
		padding-top: 87rpx;
		padding-bottom: 10rpx;
	}





	.look_details {
		margin-top: 75rpx;
		border-radius: 51rpx 51rpx;
		padding: 20rpx 0rpx;
	}



	.right_jiage {
		margin-top: 15rpx;
	}

	.num {
		font-size: 26rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #999999;
	}

	.right_sum {
		margin-top: 28rpx;
	}

	.size {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
		margin-top: 14rpx;
	}

	.list_child {
		margin-bottom: 20rpx;
		background-color: #fff;
		padding: 30rpx 30rpx 24rpx 30rpx;
		border-radius: 20rpx;

		.code {
			padding: 14rpx 0;
			font-size: 28rpx;

			.ppbh {
				font-size: 24rpx;
				font-family: PingFang SC-Heavy, PingFang SC;
				font-weight: 800;
				color: #333333;
			}

			.daifukuan {
				font-size: 24rpx;
				font-family: PingFang SC-Heavy, PingFang SC;
				font-weight: 800;
				color: #FF0000;
				color: RGBA(255, 0, 0, 1);
			}

			.daifahuo {
				font-size: 24rpx;
				font-family: PingFang SC-Heavy, PingFang SC;
				font-weight: 800;
				color: #FF0000;
				color: rgba(250, 181, 54, 1);
			}

			.daipingjia {
				font-size: 24rpx;
				font-family: PingFang SC-Heavy, PingFang SC;
				font-weight: 800;
				color: #FF0000;
				color: rgba(0, 192, 88, 1);
			}

			.daishouhuo {
				font-size: 24rpx;
				font-family: PingFang SC-Heavy, PingFang SC;
				font-weight: 800;
				color: #FF0000;
				color: rgba(34, 141, 255, 1);
			}
		}

		.top {
			margin-top: 30rpx;
			padding-bottom: 30rpx;
			border-bottom: 1rpx solid RGBA(245, 245, 245, 1);

			.left {
				width: 140rpx;
				height: 140rpx;

				image {
					border-radius: 14rpx;
					width: 100%;
					height: 100%;
				}
			}

			.right {
				flex-grow: 1;
				align-self: flex-start;
				margin-left: 20rpx;

				.right_top {
					.name {
						width: 400rpx;
						color: #000000;
						font-family: 800;
						font-size: 28rpx;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
					}
				}
			}
		}

		.center {
			margin-top: 20rpx;
			padding-bottom: 20rpx;
			border-bottom: 2rpx solid #F3F3F3;
		}

		.bottom {
			margin-top: 40rpx;

			.deldingdan {
				padding: 15rpx 30rpx;
				color: #666666;
				border: 1rpx solid #666666;
				border-radius: 35rpx;
				font-size: 24rpx;
				text-align: center;
				margin-left: 30rpx;
			}

			.confirm {
				padding: 15rpx 30rpx;
				color: RGBA(34, 141, 255, 1);
				border: 1rpx solid RGBA(34, 141, 255, 1);
				border-radius: 35rpx;
				font-size: 24rpx;
				margin-left: 30rpx;
				text-align: center;
			}
		}
	}
</style>